package com.itheima.communication;

/**
 * @author Anomaly
 * @date 2023/2/10 17:06
 */
public class ThreadDemo {
    public static void main(String[] args) {
        Account account = new Account(0);
        new DrawThread(account, "小明").start();
        new DrawThread(account, "小红").start();
        new DepositThread(account, "亲爹").start();
        new DepositThread(account, "干爹").start();
        new DepositThread(account, "岳父").start();
    }
}

class DrawThread extends Thread {
    private Account account;

    public DrawThread(Account account, String name) {
        super(name);
        this.account = account;
    }

    @Override
    public void run() {
        while (true) {
            account.drawMoney(10);
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

class DepositThread extends Thread {
    private Account account;

    public DepositThread(Account account, String name) {
        super(name);
        this.account = account;
    }

    @Override
    public void run() {
        while (true) {
            account.depositMoney(10);
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}